Skip to content

fix(libc): set ERANGE for decimal subnormals in wcstod as strtod does - #11892

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/libc-wcstod-subnormal-erange
Nov 2, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:windows/libc-wcstod-subnormal-erange

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

strtod sets ERANGE for a decimal input whose result is a nonzero subnormal (#9833). wcstod parses through the host strtod directly, so it skips that rule and leaves errno alone. The wcstod of the libc.prx that titles ship sets ERANGE in the same cases as its strtod. wcstod now parses through strtod, as #9833 offered as a follow-up.

Tested

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, main 8ff4baf.

  • Comparison: a scratch loader runs the decrypted libc.prx of eleven titles natively: PPSA04158, PPSA05916, PPSA07923, PPSA09614, PPSA13934, PPSA20423, PPSA25636, PPSA26528, PPSA33655, PPSA34008 and PPSA35169.
    • Measured cases:

      Input Bits errno
      1e-310 000012688b70e62b ERANGE
      -4.9406564584124654e-324 8000000000000001 ERANGE
      1e-330 0 ERANGE
      2.2250738585072014e-308 0010000000000000 0
      0x1p-1074 1 0
      0x1.8p-1075 1 ERANGE
      -0x1.000001p-1075 8000000000000001 ERANGE
    • Their wcstod gives these results, and all eleven set ERANGE for 1e-310, 4.9406564584124654e-324 and 0x1.8p-1075.

    • Random strings: 100,000 random decimal strings in the subnormal range (exponents -300 to -329) went through PPSA07923's wcstod and main's.

      • main differs on 40,900, every one in errno.
      • strtod matches on all 100,000, which shows the rule wcstod now reuses.
  • guest_math: CheckFloatUnderflowErrno gains the seven wcstod cases above.
  • guest_math and guest_wide_strings pass in three runs out of three on the exact head.
  • Negative control: with main's Strings.cpp and these tests, guest_math aborts (exit 0xc0000409).
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Not tested: a console's libSceLibcInternal.sprx wcstod (the debt entry keeps that as unmeasured), Linux and macOS (the change is target-independent).

Current Linux qualification (2026-10-28)

Rebased onto main 2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at 6219aaaff1520be4d484d6b618c3c3977024be58 (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).

libc, guest_math_tests and guest_math_exact_tests rebuilt from this exact source. guest_math and guest_math_exact each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.

Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256 1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.

Current Linux qualification — 2026-10-29

Refreshed against main 5454cd2e455994d992aca39335ce60507eeda1eb.

Linux qualification at f6ca8993e813d818781a29f86148c52f58df4d4b (Arch Linux 7.2.9, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON): guest_math, guest_math_exact, guest_dinkumware_internals, guest_wide_strings, guest_strtod_subnormal, guest_wide_conversion each pass three consecutive runs (18/18, no skips). The public_headers audit passes at this exact head. All tracked public-header files match the pinned main; the affected test targets rebuild against those headers. Conventions and whitespace checks pass. The same focused groups passed three times on the pinned main.

The combined debt entry retains the decimal wcstod qualification, the PPSA08329-only hexadecimal measurements and glibc 2.35 rounding limitation from merged #12291, with console wcstod still unmeasured. The focused set includes inherited hexadecimal-underflow cases and wide-string conversions. No new title measurements are claimed.

Evidence: immutable Linux qualification bundle. Its SHA-256 is 53b095da2f67f55b8aa56ba273681e0330fb39739be844458038dde410fb8cc4. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins.

AI-assisted: yes (Codex).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the delegation and the errno rule: wcstod still parses the ASCII prefix and maps endptr through ParseAsciiPrefix, while the delegated strtod_nid_postfix adds the same decimal nonzero-subnormal ERANGE behavior as strtod. I built and ran guest_math on native Linux using this PR's exact Strings.cpp and GuestMath.cpp changes; 1/1 passed. The hosted Windows build also passes, along with conventions and the Linux relinker checks. I found no blocking issue in this focused change. The console libSceLibcInternal behavior remains explicitly documented as unmeasured.

@JJenkx

JJenkx commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Linux run at this PR's exact head 01f637224c (01f637224c643c9c4c88a4f6ac6c7c318cebcd0a), not merged onto anything else; its base on main is 8ff4baf534.

Arch Linux, kernel 7.2.9, Ryzen 9 7950X, g++ (GCC) 16.2.1 20260810, glibc 2.44, x86-64. Release, BUILD_TESTING=ON.

Passed in each of 3 runs, exit code 0 each time, with no failed, skipped or not-run tests:

  • guest_math
  • guest_strings

These are the focused tests only; no title or console was used.

AI-assisted: yes (Claude Code).

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libc/src/Strings.cpp
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6295 core/libs/tests/GuestMath.cpp
PR 6565 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 core/libs/prx/libc/src/Strings.cpp
docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 10405 docs/dev/debt/libc.md
PR 10987 docs/dev/debt/libc.md
PR 11260 core/libs/tests/GuestMath.cpp
docs/dev/debt/libc.md
PR 11262 core/libs/tests/GuestMath.cpp
docs/dev/debt/libc.md
PR 11266 core/libs/tests/GuestMath.cpp
docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11831 docs/dev/debt/libc.md
PR 12057 docs/dev/debt/libc.md
PR 12292 docs/dev/debt/libc.md
PR 12560 docs/dev/debt/libc.md
PR 13390 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md
PR 14373 docs/dev/debt/libc.md
PR 14585 docs/dev/debt/libc.md
PR 14610 docs/dev/debt/libc.md

@github-actions github-actions Bot added libc docs needs rebase Conflicts with main, rebase needed labels Oct 27, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@JJenkx
JJenkx force-pushed the windows/libc-wcstod-subnormal-erange branch from 01f6372 to 6219aaa Compare October 28, 2026 12:30
@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 2227f1366188cda5699dd20e2e756a18006a5d4b. Linux CPU validation on 2026-10-28 at 6219aaaff1520be4d484d6b618c3c3977024be58 (Arch Linux 7.2.9, AMD Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON).

libc, guest_math_tests and guest_math_exact_tests rebuilt from this exact source. guest_math and guest_math_exact each passed three consecutive runs (6/6, no skips); the same two suites each passed three runs on the pinned main (6/6). Conventions and whitespace checks pass.

Exact source pins, preservation proofs, dependency checks, build logs and JUnit, SHA-256 1176269c9e6948b5252a5db9e660978d7f978fb2d9f4ed6c68bc050b10b5ae68. This is focused Linux CPU qualification; earlier Windows/title/reference measurements retain their original pins. No new title or performance result is claimed.

AI-assisted: yes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 28, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 28, 2026
@B-Howell

Copy link
Copy Markdown
Contributor

@JJenkx #12291 has now landed in main as 45f40b505d1bc40ba37f4baa6eb0153155ba54d9.

At this PR's current 6219aaaff1520be4d484d6b618c3c3977024be58, the strtod debt paragraph replaces the same line and still ends with the hexadecimal rule being unverified. When refreshing onto main, please compose your decimal wcstod qualification with the landed paragraph's PPSA08329-only hexadecimal measurements and glibc 2.35 rounding limitation, keeping the console wcstod behavior explicitly unmeasured. Neither set of measurements should be dropped when resolving that line.

The wcstod implementation here now calls strtod_nid_postfix, so please rerun the focused math/wide-string tests on the updated combined head, including the hexadecimal-underflow cases inherited from #12291. The earlier Windows/Linux results retain their recorded heads and bases; this follow-up does not report a new combined test or title result.

AI-assisted: yes (Codex).

wcstod parsed through the host strtod directly, so a decimal input with
a nonzero subnormal result left errno alone, where strtod sets ERANGE.
The wcstod of the libc.prx bundled with eleven titles sets it in the
same cases as their strtod: 1e-310, the smallest subnormal and 1e-330
set it, 2.2250738585072014e-308 and 0x1p-1074 do not, and 0x1.8p-1075
does. wcstod now parses through strtod.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx
JJenkx force-pushed the windows/libc-wcstod-subnormal-erange branch from 6219aaa to f6ca899 Compare October 29, 2026 13:12
@JJenkx

JJenkx commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed against main 5454cd2e455994d992aca39335ce60507eeda1eb.

Linux qualification at f6ca8993e813d818781a29f86148c52f58df4d4b (Arch Linux 7.2.9, Ryzen 9 7950X, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON): guest_math, guest_math_exact, guest_dinkumware_internals, guest_wide_strings, guest_strtod_subnormal, guest_wide_conversion each pass three consecutive runs (18/18, no skips). The public_headers audit passes at this exact head. All tracked public-header files match the pinned main; the affected test targets rebuild against those headers. Conventions and whitespace checks pass. The same focused groups passed three times on the pinned main.

The combined debt entry retains the decimal wcstod qualification, the PPSA08329-only hexadecimal measurements and glibc 2.35 rounding limitation from merged #12291, with console wcstod still unmeasured. The focused set includes inherited hexadecimal-underflow cases and wide-string conversions. No new title measurements are claimed.

Evidence: immutable Linux qualification bundle. Its SHA-256 is 53b095da2f67f55b8aa56ba273681e0330fb39739be844458038dde410fb8cc4. No fresh Windows runtime execution is claimed; older measurements retain their recorded source pins.

AI-assisted: yes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 29, 2026
@oneandonlydean
oneandonlydean merged commit f133e5e into boykopovar:main Nov 2, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants